package com.ddstation.doctor_verify.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpSession;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ddstation.common.service.DataDictionaryService;
import com.ddstation.crm.login.bean.SessionLoginData;
import com.ddstation.doctor_verify.service.DoctorVerifyService;
import com.ddstation.master.entity.MaDataDictionaryEntity;
import com.ddstation.master.utils.DataDictionaryCons;
import com.ddstation.sewage.service.SewageService;

/**
 * 医师备案模块
 * */
@Controller @Lazy
public class DoctorVerifyController {
	
	/**
	 * 数据查询接口
	 * 
	 * @return
	 */
	@RequestMapping(value="invs_doctor_verify.do/load_list", method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> loadDoctorVerifyListEvent(
			@RequestParam String institutionId,
			@RequestParam(required=false) String doctorName,
			HttpSession session){
		
		SessionLoginData loginData = (SessionLoginData)session.getAttribute(SessionLoginData.KEY );
		
		Map<String, Object> ret = new HashMap<String, Object>();
		ret.put("errcode", -1);
		ret.put("errMsg", "系统出错，请稍后再试！");
		
		// 访问权限check(防止异常调用)
 		if ( !sewageService.checkAccessAuthority(loginData.getInstitution().getId(),institutionId) ){
 			ret.put("errMsg", "没有访问权限！");
 			return ret;
 		}
 		/** 执业范围 医生   */
 		List<MaDataDictionaryEntity> scopePracticeList = dataDictionaryService.getCodeList(DataDictionaryCons.CODE_SCOPE_PRACTICE);
		if ( scopePracticeList == null || scopePracticeList.size()==0 ){
			throw new RuntimeException("code表数据未配置！执业范围 scope_practice");
		}
		/** 门诊 职称 医生   */
 		List<MaDataDictionaryEntity> titleList = dataDictionaryService.getCodeList(DataDictionaryCons.CODE_TECHNICAL_TITLE);
 		if ( titleList == null || titleList.size() ==0	){
 			throw new RuntimeException("code表数据未配置！职称 technical_title");
 		}
		/** 门诊 抗菌药物标记 */
		List<MaDataDictionaryEntity> antibiosisList = dataDictionaryService.getCodeList(DataDictionaryCons.CODE_ANTIBIOSIS_FLG);
		if ( titleList == null || titleList.size() ==0	){
			throw new RuntimeException("code表数据未配置！抗菌药物标记 antibiosis_flg");
		}
 		ret.put("scopePracticeList", scopePracticeList); 
 		ret.put("titleList", titleList);
 		ret.put("antibiosisList", antibiosisList);
 		
 		ret.put("datalist", doctorVerifyService.searchDoctorList(institutionId,doctorName)); 
        
		ret.put("errcode", 0);
		ret.put("errMsg", "");
		return ret;
	}
	
	@Inject private DoctorVerifyService doctorVerifyService;
	@Inject private SewageService sewageService;
	@Inject private DataDictionaryService dataDictionaryService;
	
}
